package vn.co.thn.android.videohot;

import java.util.Locale;

import vn.co.thn.android.serviceconnect.AppBase;
import vn.co.thn.android.serviceconnect.callback.RequestError;
import vn.co.thn.android.serviceconnect.request.RequestService;
import android.provider.Settings.Secure;
import android.widget.ImageView;

import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;

public class VHApp extends AppBase implements RequestError{
	public static final String TAG = VHApp.class.getSimpleName();

	private static VHApp mInstance;
	private static RequestService mRequestService;

	@Override
	public void onCreate() {
		super.onCreate();
		mInstance = this;
		mRequestService = new RequestService(mInstance);
		
	}

	public static synchronized RequestService getRequestService() {
		return mRequestService;
	}

	public static synchronized VHApp getInstance() {
		return mInstance;
	}

	public static VHPreferenceManager getPreference() {
		return VHPreferenceManager.createPreferenceManager(getInstance());
	}

	public static void Load_Image(String URL, ImageView imageView) {
		ImageLoader imageLoader = VHApp.getInstance().getImageLoader();
		
		imageLoader.get(URL.replace("localhost", "10.0.3.2"), ImageLoader
				.getImageListener(imageView, R.drawable.ic_launcher,
						R.drawable.ic_launcher));
	}

	public static String getLanguage() {
		return Locale.getDefault().getLanguage();
	}

	public static String getDeviceID() {
		if (VHApp.getPreference().getDeviceID() != null) {
			return VHApp.getPreference().getDeviceID();
		} else {
			return Secure.getString(mInstance.getContentResolver(),
					Secure.ANDROID_ID);
		}

	}

	@Override
	public void onError(VolleyError error) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onException(Exception e) {
		// TODO Auto-generated method stub
		
	}
}
